<?php
/**
 * ErrorController
 *
 * @author Holger Lampe
 * @version
 */
class ErrorController extends Zend_Controller_Action
{
    protected $_error = null;

    protected $_state = null;

    public function init()
    {
        $this->_error = $this->_getParam('error_handler');
        $this->_state = Bootstrap::getInstance()->getApplicationState();
    }

    public function errorAction()
    {
        switch ($this->_error->type) {
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
                $this->_forward('not-found');
                return;
            case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_OTHER:
                $this->_forward('server-error');
                return;
        }
    }

    public function notFoundAction()
    {
        if ($this->_state === 'development') {
            echo "<pre>Error Request:\n\n</pre>";
            Zend_Debug::dump($this->_error->request);
            echo "<pre>Exception:\n\n</pre>";
            Zend_Debug::dump($this->_error->exception);
            die('DEBUG: died in ' . __FUNCTION__);
        } else {
            $this->_response->setHttpResponseCode(404);
            $this->render();
        }

    }

    public function serverErrorAction()
    {
        if ($this->_state === 'development') {
            echo "<pre>Error Request:\n\n</pre>";
            Zend_Debug::dump($this->_error->request);
            echo "<pre>Exception:\n\n</pre>";
            Zend_Debug::dump($this->_error->exception);
            die('DEBUG: died in ' . __FUNCTION__);
        } else {
            $this->_response->setHttpResponseCode(500);
            $this->render();
        }

    }

}
